package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.mapper.BaseProductManageMapper;
import com.kaili.basic.pojo.dto.BaseProductAddDto;
import com.kaili.basic.pojo.dto.BaseProductQueryDto;
import com.kaili.basic.pojo.entity.BaseProductExport;
import com.kaili.basic.pojo.entity.BaseProductManage;
import com.kaili.basic.service.BaseProductManageService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class BaseProductManageServiceImpl implements BaseProductManageService {

    @Autowired
    private BaseProductManageMapper productManageMapper;

    @Override
    public void addProductManage(BaseProductAddDto productAddDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseProductManage productManage = new BaseProductManage();
        BeanUtils.copyProperties(productAddDto, productManage);
        if (uid != null) {
            productManage.setCreateBy(uid.longValue());
            productManage.setCreateTime(new Date());
            productManageMapper.addProductManage(productManage);
        }
    }

    @Override
    public void deleteProductManage(Long productId) {
        productManageMapper.deleteProductManage(productId);
    }

    @Override
    public void updateProductManage(BaseProductAddDto productAddDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseProductManage productManage = new BaseProductManage();
        BeanUtils.copyProperties(productAddDto, productManage);
        if (uid != null) {
            productManage.setModifyBy(uid.longValue());
            productManage.setModifyTime(new Date());
            productManageMapper.updateProductManage(productManage);
        }
    }

    @Override
    public Page<BaseProductManage> queryProductManage(Page<BaseProductManage> page, BaseProductQueryDto queryDto) {
        List<BaseProductManage> list = productManageMapper.queryProductManage(page, queryDto);
        return page.setRecords(list);
    }

    @Override
    public List<BaseProductExport> queryProductManageExport(BaseProductQueryDto queryDto) {
        return productManageMapper.queryProductManageExport(queryDto);
    }

    @Override
    public String getProductManageCode() {
        return productManageMapper.getProductManageCode();
    }

    @Override
    public List<BaseProductManage> queryBaseProductManageLike(BaseProductQueryDto queryDto) {
        return productManageMapper.queryProductManage(queryDto);
    }

    @Override
    public BaseProductManage getProductById(Long id) {
        return productManageMapper.getProductById(id);
    }
}
